import mongoose from 'mongoose';

const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
const AbilityScoreSchema = new Schema({
    schoolId: {
        type: ObjectId,
        ref: 'School'
    },
    gradeId: {
        type: ObjectId,
        ref: 'Grade'
    },
    classId: {
        type: ObjectId,
        ref: 'Clazz'
    },
    className: {
        type: String,
    },
    examId: {
        type: ObjectId,
        ref: 'Exam'
    },
    examGroupId: {
        type: ObjectId,
        ref: 'ExamGroup'
    },
    prevExamId: {
        type: ObjectId,
        ref: 'Exam'
    },
    type: Number,//1理科，2文科，3艺体, 4通用
    //上次相同考试组的id
    prevExamGroupId: {
        type: ObjectId,
        ref: 'ExamGroup'
    },
    subjectId: {
        type: ObjectId,
        ref: 'Subject'
    },
    abilityId: {
        type: ObjectId,
        ref: 'Ability'
    },
    parentAbilityId: {
        type: ObjectId,
        ref: 'Ability'
    },
    studentId: {
        type: ObjectId,
        ref: 'User'
    },
    parentAbilityName: String,
    abilityName: String,
    studentName: String,
    score: Number,
    createdAt: Date,
    updatedAt: Date
})

AbilityScoreSchema.pre('save', function (next) {
    this.createdAt = new Date();
    next();
});

let abilityScoreModel = mongoose.model('AbilityScore', AbilityScoreSchema);

export default abilityScoreModel;